//
//  CrazyChatMineGoodsCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/15.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatMineGoodsCell.h"

@interface CrazyChatMineGoodsCell ()

@property (nonatomic, strong) UIImageView *mineHeadImageView; //头像
@property (nonatomic, strong) UIView *mineGoodsBackView; //背景
@property (nonatomic, strong) UIImageView *mineGoodsBackImageView; //背景图片
@property (nonatomic, strong) UIImageView *mineGoodsImageView; //图片
@property (nonatomic, strong) UILabel *mineGoodsTitleLabel; //标题
@property (nonatomic, strong) UILabel *mineGoodsPriceLabel; //价格

@end

@implementation CrazyChatMineGoodsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = CrazyChatMineGoodsIdentifier;
    
    //缓存中取
    CrazyChatMineGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell) {
        cell = [[CrazyChatMineGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        self.mineHeadImageView = [[UIImageView alloc] init];
        self.mineHeadImageView.frame = CGRectMake(CRAZY_SCREEN_WIDTH - 55, 10, 40, 40);
        [self.contentView addSubview:self.mineHeadImageView];
        //背景
        self.mineGoodsBackView = [[UIView alloc] init];
        self.mineGoodsBackView.frame = CGRectMake(60, 10, CRAZY_SCREEN_WIDTH - 120, 100);
        [self.contentView addSubview:self.mineGoodsBackView];
        //背景图片
        self.mineGoodsBackImageView = [[UIImageView alloc] init];
        self.mineGoodsBackImageView.frame = self.mineGoodsBackView.bounds;
        self.mineGoodsBackImageView.image = [[UIImage imageNamed:@"Crazy_chat_rightPic@2x.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(23, 15, 7, 15) resizingMode:UIImageResizingModeStretch];
        [self.mineGoodsBackView addSubview:self.mineGoodsBackImageView];
        //图片
        self.mineGoodsImageView = [[UIImageView alloc] init];
        self.mineGoodsImageView.frame = CGRectMake(8, 10, 80, 80);
        [self.mineGoodsBackView addSubview:self.mineGoodsImageView];
        //标题
        self.mineGoodsTitleLabel = [[UILabel alloc] init];
        self.mineGoodsTitleLabel.numberOfLines = 2;
        self.mineGoodsTitleLabel.font = [UIFont systemFontOfSize:14];
        self.mineGoodsTitleLabel.textColor = CRAZY_RGBR(33);
        [self.mineGoodsBackView addSubview:self.mineGoodsTitleLabel];
        //价格
        self.mineGoodsPriceLabel = [[UILabel alloc] init];
        self.mineGoodsPriceLabel.textColor = [UIColor redColor];
        self.mineGoodsPriceLabel.font = [UIFont systemFontOfSize:14];
        [self.mineGoodsBackView addSubview:self.mineGoodsPriceLabel];
        [self.mineGoodsPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(93);
            make.bottom.mas_equalTo(-10);
            make.width.mas_equalTo(self.mineGoodsBackView.width - 105);
        }];
        //查看
        self.mineGoodsCheckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.mineGoodsCheckBtn.frame = self.mineGoodsBackView.bounds;
        [self.mineGoodsBackView addSubview:self.mineGoodsCheckBtn];
        //重发按钮
        self.mineGoodsRepeatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mineGoodsRepeatBtn setImage:[UIImage imageNamed:@"Crazy_chat_repeat.png"] forState:UIControlStateNormal];
        self.mineGoodsRepeatBtn.size = CGSizeMake(30, 30);
        self.mineGoodsRepeatBtn.x = 20;
        self.mineGoodsRepeatBtn.y = 10 + self.mineGoodsBackView.height / 2 - 15;
        [self.contentView addSubview:self.mineGoodsRepeatBtn];
    }
    return self;
}


//赋值
- (void)setCellValueWithHeadURL:(NSString *)headURL picURL:(NSString *)picURL title:(NSString *)title price:(NSString *)price repeatType:(NSString *)repeatType {
    //头像
    [self.mineHeadImageView sd_setImageWithURL:[NSURL URLWithString:headURL] placeholderImage:CRAZY_DEFAULT_HEADIMAGE];
    //图片
    [self.mineGoodsImageView sd_setImageWithURL:[NSURL URLWithString:picURL] placeholderImage:CRAZY_DEFAULT_LOADIMAGE];
    //标题
    self.mineGoodsTitleLabel.text = title;
    CGSize maxSize = CGSizeMake(self.mineGoodsBackView.width - 90, 40);
    CGSize size = [self.mineGoodsTitleLabel sizeThatFits:maxSize];
    self.mineGoodsTitleLabel.frame = CGRectMake(93, 10, self.mineGoodsBackView.width - 105, size.height);
    //价格
    self.mineGoodsPriceLabel.text = [NSString stringWithFormat:@"%@%@", @"¥", price];
    //重发按钮
    if ([repeatType isEqualToString:@"1"]) {
        self.mineGoodsRepeatBtn.hidden = NO;
    } else {
        self.mineGoodsRepeatBtn.hidden = YES;
    }
}








- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
